package com.a.learning_keep.base

import android.content.Context
import android.os.Bundle
import android.view.Gravity
import android.widget.LinearLayout
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.core.view.get
import androidx.viewbinding.ViewBinding
import com.a.learning_keep.R


abstract class BaseActivity<T : ViewBinding> : AppCompatActivity() {

    lateinit var binding: T
    lateinit var context: Context

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        context = this
        binding = getBind()
        setContentView(binding.root)
        initView()
    }

    abstract fun getBind(): T
    abstract fun initView()

    fun setTit(tit: String) {
        findViewById<Toolbar>(R.id.toolbar).apply {
            getChildAt(0).setOnClickListener { finish() }
            (getChildAt(1) as TextView).text = tit
        }
    }

    fun setTitContent(tit: String) {
        findViewById<Toolbar>(R.id.toolbar).apply {
            getChildAt(0).setOnClickListener { finish() }
            (getChildAt(1) as TextView).apply {
                gravity = Gravity.CENTER
                text = tit
            }
        }
    }


}